import 'package:chathouse/model/privacy_bean.dart';
import 'package:chathouse/pages/login/my_web_view.dart';
import 'package:chathouse/public/Config.dart';
import 'package:chathouse/util/base_utils.dart';
import 'package:chathouse/widgets/base_appbar.dart';
import 'package:chathouse/widgets/form_widgets/form_widgets.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../constant/app_constant.dart';
import '../../login/my_web_view_asset_html.dart';

///使用条款
class UseClausePage extends StatefulWidget {
  int? initialIndex;

  UseClausePage({Key? key, this.initialIndex}) : super(key: key);

  @override
  State<UseClausePage> createState() => _UseClausePageState();
}

class _UseClausePageState extends State<UseClausePage> {
  PrivacyBean? privacyBean;

  @override
  void initState() {
    super.initState();
    getAgreeData();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar(
          title: "屋測測平台使用條款",
          titleTextStyle: getTextStyle(28.sp,
              color: Colors.black, fontType: FontType.BOLD)),
      body: Column(
        children: [
          Expanded(
              child: SizedBox(
                child:
                // privacyBean == null
                // ? Container()
                // : MyWebView(privacyBean?.userServicesAgreement ?? ""),
                MyWebViewAssetHtml('assets/user_services_agreement.html'),
              ).setContainer(
                  margin: EdgeInsets.only(left: 20.w, right: 20.w, top: 14.w),
                  decoration: BoxDecoration(
                      border: Border.all(
                          color: MyColors.gary_112112112, width: 1.w)))),
          Row(
            children: [
              Expanded(
                  child: FormWidgets.getTextButton(
                "確認並返回",
                AppConstant.userRole == UserRole.c
                    ? MyColors.green_79141891
                    : MyColors.gary_69157154,
              ).setOnClickListener(() {
                Get.back(result: true);
              }))
            ],
          ).setContainer(
              margin: EdgeInsets.only(
                  left: 80.w, right: 80.w, bottom: 32.w, top: 32.w)),
        ],
      ),
    );
  }

  void getAgreeData() async {
    PrivacyBeanTool result;
    Obj.showLoading();
    Apis.getPrivacy()
        .then((response) => {
              Obj.dismissLoading(),
              result = PrivacyBeanTool.fromJson(response?.data ?? {}),
              if (result.isRequestSuccess)
                {
                  setState(() {
                    privacyBean = result.data;
                  })
                }
            })
        .catchError((error) => {Obj.dismissLoading(), setState(() {})});
  }
}
